package org.demo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.demo.entity.*;
import org.demo.mapper.CommunityMapper;
import org.demo.mapper.PerformanceMapper;
import org.demo.service.ICommunityService;
import org.demo.service.IOrderIdService;
import org.demo.service.IPerformanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Service
public class PerformanceServiceImpl extends ServiceImpl<PerformanceMapper, Performance> implements IPerformanceService {
    @Autowired
    private PerformanceMapper performanceMapper;
    @Autowired
    private IOrderIdService orderIdService;


    @Override
    public void add(Performance performance) {
        String id = orderIdService.getId("PERF");
        performance.setId(id);
        save(performance);
    }
    @Override
    public PageBean<Performance> Pagelist(Integer pageNum, Integer pageSize, Performance performance) {
        // 创建 pagebean 对象
        PageBean<Performance> pb = new PageBean<>();
        // 开启分页查询
        Page<Performance> page = PageHelper.startPage(pageNum, pageSize);


        List<Performance> performanceList = new ArrayList<>();


        pb.setTotal(page.getTotal());
        pb.setItems(performanceList);
        return pb;
    }
    @Override
    public List<Performance> list(Performance performance) {
        List<Performance> performances=lambdaQuery().eq(Performance::getId,performance.getId()).list();
        return performances;
    }

    @Override
    public void update(Performance performance) {
        lambdaUpdate().eq(Performance::getId,performance.getId()).update();
    }

    @Override
    public void delete(String id) {
        performanceMapper.deleteById(id);
    }
}
